package com.older.wptsb.controller;


import com.older.wptsb.domain.dto.UpdatePasswordDTO;
import com.older.wptsb.domain.dto.UserBackDTO;
import com.older.wptsb.domain.dto.UserLoginDTO;
import com.older.wptsb.domain.dto.UserRegisterDTO;
import com.older.wptsb.domain.po.RequireRole;
import com.older.wptsb.domain.po.UserRole;
import com.older.wptsb.domain.vo.UserLoginVO;
import com.older.wptsb.service.UserService;
import com.older.wptsb.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;


    @PostMapping("/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        if (userLoginVO == null)
            return Result.error("用户名或密码错误");
        return Result.success(userLoginVO);
    }
    @PostMapping("/register")
    public Result<String> register(@RequestBody UserRegisterDTO userRegisterDTO){
            userService.register(userRegisterDTO);
            return Result.success("注册成功");
    }
    @PostMapping("/back")
    public Result<String> back(@RequestBody UserBackDTO userBackDTO){
        userService.back(userBackDTO);
        return Result.success("认证成功，请重新修改密码");
    }
    @PostMapping("/back/Password")
    public Result<String> backPassword(@RequestBody UpdatePasswordDTO updatePasswordDTO){
        userService.backPassword(updatePasswordDTO);
        return Result.success("修改成功,请重新登录");
    }
}
